<?php

namespace fztadmin\modules\custom\controllers;

use common\models\db\User;
use fztadmin\modules\custom\models\searches\FundTransactionDetailsFilter;
use yii\data\Pagination;
use yii\web\Controller;

class FundTransactionDetailsController extends Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionIndex01()
    {
        $this->view->title = "普通资金分户交易明细";
        return $this->_index("01");
    }

    public function actionIndex02()
    {
        $this->view->title = "交易手续费分户交易明细";
        return $this->_index("02");
    }

    public function actionIndex03()
    {
        $this->view->title = "提现手续费分户交易明细";
        return $this->_index("03");
    }

    public function actionIndex04()
    {
        $this->view->title = "营销费用分户交易明细";
        return $this->_index("04");
    }

    public function actionIndex05()
    {
        $this->view->title = "鉴权分户交易明细";
        return $this->_index("05");
    }

    public function actionIndex11()
    {
        $this->view->title = "待清算资金分户交易明细";
        return $this->_index("11");
    }

    public function actionIndex12()
    {
        $this->view->title = "预付货款分户交易明细";
        return $this->_index("12");
    }

    protected function _index($acctType)
    {
        /**
         * @var User $user
         */
        $user = \Yii::$app->user->identity;
        $custom = $user->custom;
        if (!$custom){
            throw new \Exception("未找到子账户");
        }
        if (!$custom->plat_cust_no){
            throw new \Exception("未找到子账户客户编号，请联系工作人员");
        }
        $model = new FundTransactionDetailsFilter();
        $model->validate();
        if ($model->load(\Yii::$app->request->get()) && $model->validate()) {}else{
            $model = new FundTransactionDetailsFilter();
        }
        $transId = uniqid();
        $params = [
            'transId' => $transId,
            'platCustNo' => $custom->plat_cust_no,
            'acctType' => $acctType,
            'bgnDate' => $model->begin_date,
            'endDate' => $model->end_date,
            'pageNo' => \Yii::$app->request->get('page'),
            'pageSize' => 20,
        ];

        $fzt = \Yii::$app->fenZhangTong;
        $fzt->IESI111107($params);
        if ($fzt->ret_code != "00000") {
            throw new \Exception($fzt->ret_msg);
        }
        $pagination = new Pagination(['totalCount' => $fzt->resp_arr['totalRecord']]);
        return $this->render('_list', [
            'list' => $fzt->resp_arr['dataList'],
            'total' => $fzt->resp_arr['totalRecord'],
            'pagination' => $pagination,
            'model' => $model,
        ]);
    }
}